# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@ovgu.de>
pkgname=afl
pkgver=2.57b
pkgrel=2
pkgdesc="Fuzzer relying on genetic algorithms instead of brute force"
url="https://lcamtuf.coredump.cx/afl/"
# arch="all !x86" fails to build
license="Apache-2.0"
options="!check" # no tests provided
depends="clang llvm"
makedepends="clang-dev llvm-dev"
subpackages="$pkgname-doc $pkgname-clang:_clang $pkgname-gcc:_gcc"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/AFL/archive/v$pkgver.tar.gz"
builddir="$srcdir/AFL-$pkgver"

build() {
	export CC=clang
	make AFL_NO_X86=1 PREFIX=/usr
	make -C llvm_mode AFL_NO_X86=1 PREFIX=/usr
}

package() {
	make AFL_NO_X86=1 PREFIX=/usr DESTDIR="$pkgdir" install
	install -Dm644 llvm_mode/README.llvm \
		"$pkgdir"/usr/share/doc/$pkgname/README.llvm_mode

	# small_exec.elf is an Intel binary which causes an error during
	# the strip() process on non Intel plattforms.
	case "$CARCH" in
		x86*) ;;
		*) rm -f "$pkgdir"/usr/share/afl/testcases/others/elf/small_exec.elf ;;
	esac
}

_clang() {
	description="$pkgdesc - CLang instrumention support"
	depends="clang"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/afl-clang \
		"$pkgdir"/usr/bin/afl-clang++ \
		"$subpkgdir"/usr/bin
}

_gcc() {
	description="$pkgdesc - GCC instrumention support"
	depends="gcc"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/afl-gcc \
		"$pkgdir"/usr/bin/afl-g++ \
		"$subpkgdir"/usr/bin
}

sha512sums="5d12b96229e966aeb11deb47cd8eb36cde2fa32656eb187db02c7240909d6acda36be59b2baf7e42cddd228d25ec94c8bffc3fa27f7f4b5e1e462b62929ce75d  afl-2.57b.tar.gz"
